home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2005 October / PCWOCT05.iso / Software / FromTheMag / Ant Movie Catalog 3.5.0.2 / amc_install.exe / {app} / Scripts / Amazon (FR).ifs < prev    next >
Text File  |  2005-05-23  |  14KB  |  406 lines

  1. (***************************************************
  2.  
  3. Ant Movie Catalog importation script
  4. www.antp.be/software/moviecatalog/
  5.  
  6. [Infos]
  7. Authors=ScorEpioN
  8. Title=Amazon.fr
  9. Description=RΘcupΦre les informations DVD d'Amazon.fr
  10. Site=http://www.amazon.fr
  11. Language=FR
  12. Version=11 du 23/05/2005
  13. Requires=3.5
  14. Comments=Ce script nΘcessite le fichier ScorEpioNCommonScript.pas|.==.| :   ' ( ( ( ( /\ |  "==()))))):     ⌐ ScorEpioN ⌐|       ( ( ( ( \_/
  15. License=This program is free software; you can redistribute it and/or modify it under the  terms of the GNU General Public License as published by the Free Software Foundation;  either version 2 of the License, or (at your option) any later version. |
  16. GetInfo=1
  17.  
  18. [Options]
  19. Mise α jour=1|1|0=Oui|1=Non
  20. Type de Lancement=0|0|0=Demande le titre avant de lancer le script|1=Ne demande pas le titre avant de lancer le script|2=Cherche le meilleur rΘsultat sans confirmation|3=Lancement automatique sur l'adresse web
  21. Casse Choisie=3|3|0=Titre et Nom en minuscule|1=Titre et Nom en majuscule|2=PremiΦre lettre en majuscule|3=PremiΦre lettre de chaque mot en majuscule
  22. Titre en double=0|0|0=Garde les titres originaux et traduits mΩme identiques|1=Garde les titres originaux si identiques|2=Garde les titres traduits si identiques
  23. Recherche sur le titre=0|0|0=Traduit|1=Original
  24. Fichier de log=1|1|0=Oui|1=Non
  25.  
  26. ***************************************************)
  27.  
  28. program Amazon_FR;
  29. uses
  30.   ScorEpioNCommonScript;
  31.  
  32. const
  33.     VersionScript = '11 du 23/05/2005';
  34.     urlDomain = 'amazon.fr';
  35.     NomScript = 'AMAZON.FR';
  36.     AmazonUrl = 'http://www.amazon.fr/exec/obidos/ASIN/';
  37.     AmazonSearch = 'http://www.amazon.fr/exec/obidos/search-handle-url/index=dvd-fr&field-keywords=';
  38.     timetosleep = 500;
  39. var
  40.   MovieName, Address : string;
  41.   i, premiereExecution: Integer;
  42.   listeResultat: TStringList;
  43.  
  44. //------------------------------------------------------------------------------
  45. // RECUPERE LES RESULTATS AMAZON.FR
  46. //------------------------------------------------------------------------------
  47.  
  48. procedure imageAmazon(title : String);
  49. var
  50.   adresseRecherche, Line : String;
  51.   StartPos: Integer;
  52. begin
  53.   PickTreeClear;
  54.   adresseRecherche := AmazonSearch+UrlEncode(title);
  55.   Line := GetPage(adresseRecherche);
  56.   if pos('satisfaisante pour votre recherche sur', Line) > 0 then
  57.   begin
  58.     SetField(fieldChecked, '');
  59.     exit;
  60.   end else
  61.   if (pos('Sur ce DVD', Line) > 0) or (pos('Amazon.fr : DVD:', Line) > 0) then
  62.   begin
  63.       recupInfo(Line);
  64.   end else
  65.   if pos('résultats au total pour', Line) > 0 then
  66.   begin
  67.       StartPos := pos('résultats au total pour', Line);
  68.       delete(Line, 1, StartPos);
  69.       recupAmazon(Line, title);
  70.   end;
  71. end;
  72.  
  73. //------------------------------------------------------------------------------
  74. // CREATION DE LA LISTE DE RESULTAT
  75. //------------------------------------------------------------------------------
  76.  
  77. procedure recupAmazon(Line, title : String);
  78. var
  79.    StartPos : Integer;
  80.    couple, titre, adresse : String;
  81. begin
  82.  
  83.   listeResultat := TStringList.Create;
  84.   StartPos := pos('<a href=/exec/obidos/ASIN/', Line);
  85.   delete(Line, 1, StartPos-1);
  86.   repeat
  87. {*********************** Boucle DEBUT ***********************}
  88.      StartPos := pos('<a href=/exec/obidos/ASIN/', Line);
  89.      delete(Line, 1, StartPos+length('<a href=/exec/obidos/ASIN/')-1);
  90. {*********************** Boucle DEBUT ***********************}
  91. //ajoute les films
  92.      listeResultat.Add(recupTitle(Line)+'|'+AmazonUrl+copy(Line,0,pos('qid', Line)-1));
  93. {*********************** Boucle FIN ***********************}
  94.      StartPos := pos('<a href=/exec/obidos/ASIN/', Line);
  95. {*********************** Boucle FIN ***********************}
  96.   until (StartPos = 0);
  97.  
  98.   if (GetOption('Type de Lancement') = 0) or (GetOption('Type de Lancement') = 1) then
  99.   begin
  100.    PickTreeAdd('Films trouvΘs pour ' + title + ' :', '');
  101.    for i:=0 to listeResultat.Count-1 do
  102.    begin
  103.      couple := listeResultat.GetString(i);
  104.      titre := copy(couple,0,pos('|',couple)-1);
  105.      adresse := copy(couple,pos('|',couple)+1,length(couple)-1);
  106.      PickTreeAdd(titre , adresse);
  107.    end;
  108.  
  109.     if listeResultat.Count = 1 then
  110.     begin
  111.      recupInfo(adresse);
  112.      exit;
  113.     end;
  114.  
  115.     if (PickTreeExec(Address)=true) then
  116.        recupInfo(Address);
  117.        
  118.   end else if (GetOption('Type de Lancement') = 2) then
  119.   begin
  120.      trouveTitle(title);
  121.   end;
  122. end;
  123.  
  124. //------------------------------------------------------------------------------
  125. // RECUPERE LES INFOS
  126. //------------------------------------------------------------------------------
  127.  
  128. procedure recupInfo(Adresse : String);
  129. var
  130.    Value, Value2, Line: String;
  131.    StartPos: Integer;
  132. begin
  133. // Pour le mode Batch
  134.    if (GetOption('Fichier de log') = 0) then
  135.      beforeUpdate();
  136.  
  137.    Value := copy(Adresse,0,4);
  138.    if Value = 'http' then
  139.    begin
  140.         Line := GetPage(Adresse);
  141.    end else
  142.    begin
  143.        line := Adresse;
  144.        Adresse := AmazonUrl+findInfo('name="asin" value="', '">', Line,'0');
  145.    end;
  146.    StartPos := pos('<b class="sans">', Line);
  147.    delete(Line, 1, StartPos-1);
  148. // Jaquette DVD
  149.    if CanSetPicture then
  150.      GetPicture(recupImage(Line));
  151. // Titre Traduit
  152.    if CanSetField(fieldTranslatedTitle) then
  153.    begin
  154.       Value := formatTitre(findInfo('<b class="sans">', '</b>', Line,'0'),GetOption('Casse Choisie'));
  155.       delete(Value, pos(' - ',Value), length(Value));
  156.       if (pos('(',Value) > 0) then
  157.         delete(Value, pos('(',Value), length(Value));
  158.       MonSetField(fieldTranslatedTitle, Value);
  159.    end;
  160. // Acteurs
  161.    if CanSetField(fieldActors) then
  162.       MonSetField(fieldActors, formatTitre(findInfo('Avec :', '<br>', Line,'0'),GetOption('Casse Choisie')));
  163. // RΘalisateur
  164.    if CanSetField(fieldDirector) then
  165.       MonSetField(fieldDirector, formatTitre(findInfo('Réalisateur :', '<br>', Line,'0'),GetOption('Casse Choisie')));
  166. // Date de parution
  167.    if CanSetField(fieldYear) then
  168.    begin
  169.       Value := findInfo('Date de parution :', '<br>', Line,'0');
  170.       MonSetField(fieldYear, copy(Value,length(Value)-4,length(Value)));
  171.    end;
  172. // Editeur
  173.    if CanSetField(fieldProducer) then
  174.       MonSetField(fieldProducer, findInfo('Éditeur :', '<br>', Line,'0'));
  175. // Line α partir de Zone et Formats son
  176.    StartPos := pos('Zone et formats son :', Line);
  177.    delete(Line, 1, StartPos-1);
  178. // Zone
  179.    if CanSetField(fieldVideoFormat) then
  180.       MonSetField(fieldVideoFormat, 'DVD '+findInfo('Zone :', '<BR>', Line,'0'));
  181. // Langue
  182.    if CanSetField(fieldLanguages) then
  183.       MonSetField(fieldLanguages, findInfo('Langues et formats sonores :', '<BR>', Line,'0'));
  184. // Sous-titre
  185.    if CanSetField(fieldSubtitles) then
  186.       MonSetField(fieldSubtitles, findInfo('Sous-titres :', '<br>', Line,'0'));
  187. // Line α partir de DΘtails de l'Θdition
  188.    StartPos := pos('Détails', Line);
  189.    delete(Line, 1, StartPos-1);
  190. // Titre Original
  191.    if CanSetField(fieldOriginalTitle) then
  192.       MonSetField(fieldOriginalTitle, findInfo('Titre Original :', '<br>', Line,'0'));
  193. // Line α partir de Bonus
  194.    StartPos := pos('Bonus', Line);
  195.    delete(Line, 1, StartPos-1);
  196. // Bonus
  197.    if CanSetField(fieldComments) then
  198.    begin
  199.       Value := findInfo('Bonus :', '• ASIN', Line,'-1');
  200.       if Value <> '' then
  201.         Value := 'Bonus :'+Value;
  202.       MonSetField(fieldComments, Value);
  203.    end;
  204. // Line α partir de Bonus
  205.    StartPos := pos('Chroniques et points de vue', Line);
  206.    delete(Line, 1, StartPos-1);
  207. // Synopsis
  208.    if CanSetField(fieldDescription) then
  209.    begin
  210.       if pos('Liste complète des chroniques et points de vue',Line) <> 0 then
  211.       begin
  212.         StartPos := Pos('href=/exec/obidos/tg/detail',Line);
  213.         delete(Line,1,StartPos+5);
  214.         Value := copy(Line,1,Pos('/ref',Line)-1);
  215.         Line := GetPage('http://www.amazon.fr/'+Value);
  216.       end;
  217.       Value := findInfo('Synopsis</i></b></span><br>', '</span>', Line,'-1');
  218.       if Value <> '' then
  219.         Value := 'Synopsis :'+#13#10+Value+#13#10#13#10;
  220.       Value2 := Value;
  221.       Value := findInfo('Amazon.fr</i></b></span><br>', '</span>', Line,'-1')+findInfo('Amazon.fr </i></b></span><br>', '</span>', Line,'-1');
  222.       if Value <> '' then
  223.         Value := 'Avis Amazon.fr :'+#13#10+Value;
  224.       MonSetField(fieldDescription, Value2+Value);
  225.    end;
  226. // Adresse Web
  227.    if CanSetField(fieldURL) then
  228.       SetField(fieldURL, Adresse);
  229.       
  230. // Pour le mode Batch
  231.   if (GetOption('Fichier de log') = 0) then
  232.     afterUpdate();
  233.  
  234. // Affichage des titres si original et traduit identique
  235.   titreDouble(GetOption('Titre en double'));
  236.   
  237. end;
  238.  
  239. //------------------------------------------------------------------------------
  240. // RECUPERE L'ADRESSE DE L'IMAGE
  241. //------------------------------------------------------------------------------
  242.  
  243. function recupImage(Line : String) : String;
  244. var
  245.    ImageAddress : String;
  246.    StartPos: Integer;
  247. begin
  248.      StartPos := pos('http://images-eu.amazon.com/images/P/', Line);
  249.      delete(Line, 1, StartPos-1);
  250.      ImageAddress := copy(Line, 0, pos('"', Line) - 1);
  251.      ImageAddress := StringReplace(ImageAddress, 'THUMBZZZ', 'LZZZZZZZ');
  252.      result := ImageAddress;
  253. end;
  254.  
  255. //------------------------------------------------------------------------------
  256. // RECUPERE LE TITRE
  257. //------------------------------------------------------------------------------
  258.  
  259. function recupTitle(Line : String) : String;
  260. var
  261.    title : String;
  262.    StartPos: Integer;
  263. begin
  264.      StartPos := pos('<b>', Line);
  265.      delete(Line, 1, StartPos-1);
  266.      title := copy(Line, 1, pos('</b></a>', Line)-1);
  267.      HTMLRemoveTags(title);
  268.      title := StringReplace(title, #13#10, '');
  269.      result := title;
  270. end;
  271.  
  272. //------------------------------------------------------------------------------
  273. // IMPORTE L'IMAGE AMAZON
  274. //------------------------------------------------------------------------------
  275.  
  276. procedure importAmazon(Line : String);
  277. var
  278.    ImageAddress : String;
  279.    StartPos: Integer;
  280. begin
  281.      StartPos := pos('http://images-eu.amazon.com/images/P/', Line);
  282.      delete(Line, 1, StartPos-1);
  283.      ImageAddress := copy(Line, 0, pos('"', Line) - 1);
  284.      ImageAddress := StringReplace(ImageAddress, 'THUMBZZZ', 'LZZZZZZZ');
  285.      Sleep(timetosleep);
  286.      GetPicture(ImageAddress);
  287. end;
  288.  
  289.  
  290. //------------------------------------------------------------------------------
  291. // SUPPRIME LES ACCENTS
  292. //------------------------------------------------------------------------------
  293.  
  294. function supprimeAccents(NomFilm : String) : String;
  295. begin
  296.      NomFilm := supprimeLesAccents(NomFilm);
  297.      delete(NomFilm, pos(' - ',NomFilm), length(NomFilm));
  298.      if (pos(', ',NomFilm) > 0) then
  299.         delete(NomFilm, 1, pos(', ',NomFilm)+1);
  300.      if (pos('(',NomFilm) > 0) then
  301.         delete(NomFilm, pos('(',NomFilm), length(NomFilm));
  302.      if (pos(':',NomFilm) > 0) then
  303.         delete(NomFilm, pos(':',NomFilm), length(NomFilm));
  304.      result := trim(NomFilm);
  305. end;
  306.  
  307. //------------------------------------------------------------------------------
  308. // COMPARE LE TITRE PASSE ET LE TITRE TROUVE
  309. //------------------------------------------------------------------------------
  310.  
  311. function compareTitle(titleAllo, title : String) : String;
  312. begin
  313.      title := supprimeAccents(trim(AnsiLowerCase(title)));
  314.      titleAllo := supprimeAccents(trim(AnsiLowerCase(titleAllo)));
  315.      if (title = titleAllo) then
  316.      begin
  317.        result := 'OK';
  318.      end else
  319.      begin
  320.        result := 'KO';
  321.      end;
  322. end;
  323.  
  324. //------------------------------------------------------------------------------
  325. // TROUVE LE BON TITRE SI LE PREMIER N'EST PAS LE BON
  326. //------------------------------------------------------------------------------
  327.  
  328. procedure trouveTitle(title : String);
  329. var
  330.    oK, couple, titre, adresse : String;
  331. begin
  332.    for i:=0 to listeResultat.Count-1 do
  333.    begin
  334.      couple := listeResultat.GetString(i);
  335.      titre := copy(couple,0,pos('|',couple)-1);
  336.      adresse := copy(couple,pos('|',couple)+1,length(couple)-1);
  337.      oK := compareTitle(title,titre);
  338.      if oK = 'OK' then
  339.      begin
  340.        recupInfo(adresse);
  341.        exit;
  342.      end;
  343.    end;
  344.    listeResultat.Free;
  345.  
  346. end;
  347.  
  348. //------------------------------------------------------------------------------
  349. // PROGRAMME PRINCIPAL
  350. //------------------------------------------------------------------------------
  351.  
  352. begin
  353.   if CheckVersion(3,5,0) then
  354.   begin
  355.     if GetOption('Mise α jour') = 0 then
  356.     begin
  357.        execMenuMAJ(VersionScript,NomScript);
  358.        exit;
  359.     end;
  360.     MovieName := recupTitreRecherche(GetOption('Recherche sur le titre'));
  361.     if (GetOption('Fichier de log') = 0) and (premiereExecution = 0) then
  362.     begin
  363.       batch(NomScript);
  364.       AddToLog('Les films ayant ΘtΘ mis α jour sont maintenant cochΘs');
  365.     end;
  366.     if (GetOption('Type de Lancement') = 0) then
  367.     begin
  368.       if Input(NomScript+' by ScorEpioN', 'Entrez le titre du film :', MovieName) then
  369.       begin
  370.         if Pos(urlDomain, MovieName) > 0 then
  371.         begin
  372.           recupInfo(MovieName);
  373.         end else
  374.           imageAmazon(MovieName);
  375.       end;
  376.     end else
  377.     if (GetOption('Type de Lancement') = 3) then
  378.     begin
  379.       if (premiereExecution = 0) then
  380.       begin
  381.         premiereExecution := -1;
  382.         if (ShowConfirmation('Vous allez executer le script sans confirmation, cliquer sur ''''OUI'''' pour continuer') = False) then
  383.            exit;
  384.       end;
  385.       MovieName := GetField(fieldURL);
  386.       if Pos(urlDomain, MovieName) > 0 then
  387.          recupInfo(MovieName);
  388.     end else
  389.     begin
  390.       if (premiereExecution = 0) then
  391.       begin
  392.           premiereExecution := -1;
  393.           if (ShowConfirmation('Vous allez executer le script sans confirmation, cliquer sur ''''OUI'''' pour continuer') = True) then
  394.           begin
  395.             imageAmazon(MovieName);
  396.           end else
  397.             exit;
  398.       end else
  399.       begin
  400.           imageAmazon(MovieName);
  401.       end;
  402.     end;
  403.   end else
  404.     ShowMessage('This script requires a newer version of Ant Movie Catalog (at least the version 3.5.0)');
  405. end.
  406.